package com.exchange.employee.config;

import com.exchange.employee.entity.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface ArticleRepository extends ElasticsearchRepository<Article, Long> {

    @Query("{\"bool\" : {\"should\" : [ " +
            "{\"match\" : {\"title\" : {\"query\" : \"?0\", \"minimum_should_match\" : \"?1\" }}}," +
            "{\"match\" : {\"content\" : {\"query\" : \"?2\", \"minimum_should_match\" : \"?3\" }}}" +
            "] }}")

    Page<Article> findByTitleContainsOrContentContains(
            String titleKey, String titleMatch,
            String contentKey, String contentMatch,
            Pageable pageable);
}
